// 笔试强训day35:奇数位丢弃

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n = 0; 
    while(cin >> n)
    {
        vector<int> arr(n + 1);
        for(int i = 0; i <= n; i++) arr[i] = i;
        int slow = 0, fast = 0;
        n++;
        while(n > 1)
        {
            for(slow = 0, fast = 1; fast < n; slow += 1, fast += 2)
            {
                arr[slow] = arr[fast];
            }
            n = slow;
        }
        cout << arr[0] << endl;
    }
}